package com.zlzxm.shoesmarket.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.zlzxm.shoesmarket.globle.Constant;
import com.zlzxm.shoesmarket.util.RxAndroidHelp;
import com.zlzxm.shoesmarket.view.adapter.ADCalculateSize;
import com.zlzxm.shoesmarket.view.adapter.entity.EntityCalculateWholesaleInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;


/**
 * CREATE BY zlzxm ON 4/26/21
 */
public class VMWholesaleCalculate  extends ViewModel {

    private MutableLiveData<List<ADCalculateSize.EntityGoodsSizeTag>> liveSize= new MutableLiveData<>();

    private MutableLiveData<List<EntityCalculateWholesaleInfo>> liveInfo= new MutableLiveData<>();




    public MutableLiveData<List<ADCalculateSize.EntityGoodsSizeTag>> getLiveSize() {
        return liveSize;
    }


    public MutableLiveData<List<EntityCalculateWholesaleInfo>> getLiveInfo() {
        return liveInfo;
    }

    public void requestSize(){


        Observable.timer(1, TimeUnit.SECONDS)
                .compose(RxAndroidHelp.turn())
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull Long aLong) {

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                        liveSize.setValue(createTestDataSize());
                    }
                });

    }


    public  void requestInfo(){


        Observable.timer(1,TimeUnit.SECONDS)
                .compose(RxAndroidHelp.turn())
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull Long aLong) {

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                        liveInfo.setValue(createInfo());
                    }
                });


    }



    private List<ADCalculateSize.EntityGoodsSizeTag> createTestDataSize(){



        List<ADCalculateSize.EntityGoodsSizeTag> list = new ArrayList<>();



        ADCalculateSize.EntityGoodsSizeTag entityGoodsSizeTag = new ADCalculateSize.EntityGoodsSizeTag("1","35.5");


        list.add(entityGoodsSizeTag);


        ADCalculateSize.EntityGoodsSizeTag entityGoodsSizeTag1 = new ADCalculateSize.EntityGoodsSizeTag("1","36");


        list.add(entityGoodsSizeTag1);


        ADCalculateSize.EntityGoodsSizeTag entityGoodsSizeTag2 = new ADCalculateSize.EntityGoodsSizeTag("1","36.5");


        list.add(entityGoodsSizeTag2);


        ADCalculateSize.EntityGoodsSizeTag entityGoodsSizeTag3 = new ADCalculateSize.EntityGoodsSizeTag("1","37");


        list.add(entityGoodsSizeTag3);



        ADCalculateSize.EntityGoodsSizeTag entityGoodsSizeTag4 = new ADCalculateSize.EntityGoodsSizeTag("1","38");


        list.add(entityGoodsSizeTag4);

        ADCalculateSize.EntityGoodsSizeTag entityGoodsSizeTag5 = new ADCalculateSize.EntityGoodsSizeTag("1","38.5");


        list.add(entityGoodsSizeTag5);


        ADCalculateSize.EntityGoodsSizeTag entityGoodsSizeTag6 = new ADCalculateSize.EntityGoodsSizeTag("1","39");


        list.add(entityGoodsSizeTag6);


        ADCalculateSize.EntityGoodsSizeTag entityGoodsSizeTag7 = new ADCalculateSize.EntityGoodsSizeTag("1","40");


        list.add(entityGoodsSizeTag7);


        return list;



    }


    private List<EntityCalculateWholesaleInfo> createInfo(){

        List<EntityCalculateWholesaleInfo> list = new ArrayList<>();

        EntityCalculateWholesaleInfo entityCalculateWholesaleInfo = new EntityCalculateWholesaleInfo();

        entityCalculateWholesaleInfo.setTotal("45");
        entityCalculateWholesaleInfo.setCost(Constant.Character.CNY+"251");
        entityCalculateWholesaleInfo.setAvg(Constant.Character.CNY+"255");
        entityCalculateWholesaleInfo.setProfit("200%");

        list.add(entityCalculateWholesaleInfo);


        EntityCalculateWholesaleInfo entityCalculateWholesaleInfo1 = new EntityCalculateWholesaleInfo();
        entityCalculateWholesaleInfo1.setTotal("321");
        entityCalculateWholesaleInfo1.setCost(Constant.Character.CNY+"122");
        entityCalculateWholesaleInfo1.setAvg(Constant.Character.CNY+"255");
        entityCalculateWholesaleInfo1.setProfit("766%");
        list.add(entityCalculateWholesaleInfo1);

        return list;
    }




}
